#ifndef CRAPGAME_H
#define CRAPGAME_H

#include "DiceGame.h"
#include "crbet.h"

class CrapsConnection;
class CrapsRound;
class CrapsSavedGame;
class CTableLimits;

// kharmon.  06-16-06.  #3077.  Sicbo implementation.  Now inherit from DiceGame.
class CrapsGame : public DiceGame
{
	public:
		CrapsGame(CrapsConnection *conn);
		CrapsGame(CrapsConnection *conn, CrapsSavedGame *saved);
		~CrapsGame();

		// accessors
		uint8			getPoint() { return m_point; }
		CrapsRound *	getRound() { return m_round; }
		CrapsRound *	getCurrent() { return m_current; }

		// modifiers
		void	setPoint(uint8 total);
		void	setDice(uint8 die1, uint8 die2);

		// game funcs
		void	save();
		void	send(bool8 bSaved);
		uint8	roll(CrapsRound *round, int32 *balance, int32 *compBalance, int32 *bonusBalance);

		int32*		ProcessBets(CrapsRound *round, int32 *continueBets, int32 *continueBonusBets);
		int32		validateBets(CrapsRound *round);
		int32		calcPayout();
		int32		calcBonusPayout();
		int32		calcTotalWinningBets();
		int32		roundDownAmount(int32 amount);

        // kharmon.  06-16-06.  #3077.  Sicbo implementation.  Handles incoming messages from the client.
        virtual bool8 handleMessage(unsigned char *pucMsgBuf, int32 nMsgLen);

	protected:

		// game funcs
		void	restore(CrapsSavedGame *saved);
		void	returnRemovableBets();

		// bet result funcs
		void	CalcBonusWin (int32 netWin, int32 realBet, int32 bonusBet, int32 *realWin, int32 *bonusWin);

		void	Winner(uint8 betID, int32 amount);
		void	Loser(uint8 betID);
		void	Continue(uint8 betID);
		void	Push(uint8 betID);
		void	MoveComeTo(uint8 betID, uint8 number);
		void	MoveDontComeTo(uint8 betID, uint8 number);

		int32	TrueOdds(int32 betAmount, int32 theNumber);
		int32	DontTrueOdds(int32 betAmount, int32 theNumber);

		// process bet funcs
		void	ProcessPassBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessDontPassBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessPassOddsBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessDontPassOddsBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessBigBets(uint8 betID, int32 theNumber, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessComeOddsBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessComeOddsBet(uint8 betID, int32 theNumber, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessDontComeOddsBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessDontComeOddsBet(uint8 betID, int32 theNumber, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessComeNumberBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessComeNumberBet(uint8 betID, int32 theNumber, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessDontComeNumberBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessDontComeNumberBet(uint8 betID, int32 theNumber, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessBuyBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessBuyBet(uint8 betID, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessPlaceBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessPlaceBet(uint8 betID, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessPlaceLoseBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessPlaceLoseBet(uint8 betID, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessLayBets(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessLayBet(uint8 betID, int32 *continueBets, int32 *continueBonusBets);
		void	ProcessHardWays(int32 *continueBets, int32 *continueBonusBets);
		void	ProcessHardWay(uint8 betID, int32 *continueBets, int32 *continueBonusBets);

		void	ProcessComeBets();
		void	ProcessDontComeBets();

		void	ProcessFieldBet();
		void	ProcessOneShotBets();
		void	ProcessAnyCrapsBets();
		void	ProcessAnyCraps(uint8 betID);

	protected:

		CrapsConnection		*m_conn;
		CrapsRound			*m_round;
		CrapsRound			*m_current;		// the current 'state' of the game

		// Values adhere to BetState
		int32				 m_betAmounts[CrapsBet::NUMBETS]; // This is actually the payout amount on a winner
		int32				 m_bonusPayAmounts[CrapsBet::NUMBETS]; // This is the bonus payout amount

		uint8				 m_point;
		uint8				 m_die1, m_die2, m_diceTotal;

		CTableLimits		*m_tableLimits;

		//
		// *IMPORTANT*  When adding/changing here, be sure to update
		//				constructors/destructor, send(), restore()
		//



};

#endif

